package com.ruoyi.industry.controller.pc;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.industry.domain.ProjectWorkshop;
import com.ruoyi.industry.service.IProjectWorkshopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 标准厂房Controller
 *
 * @author MagicCube
 * @date 2023-06-05
 */
@RestController
@RequestMapping("/frontend/workshop")
public class PCProjectWorkshopController extends BaseController
{
    @Autowired
    private IProjectWorkshopService projectWorkshopService;

    /**
     * 查询标准厂房列表
     */
    @RequiresPermissions("myIndustry:workshop:list")
    @GetMapping("/list")
    public TableDataInfo list(ProjectWorkshop projectWorkshop)
    {
        startPage();
        projectWorkshop.setSupplyUserId(SecurityUtils.getUserId());
        List<ProjectWorkshop> list = projectWorkshopService.selectProjectWorkshopList(projectWorkshop);
        return getDataTable(list);
    }

    /**
     * 导出标准厂房列表
     */
    @RequiresPermissions("myIndustry:workshop:export")
    @Log(title = "标准厂房", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectWorkshop projectWorkshop)
    {
        projectWorkshop.setSupplyUserId(SecurityUtils.getUserId());
        List<ProjectWorkshop> list = projectWorkshopService.selectProjectWorkshopList(projectWorkshop);
        ExcelUtil<ProjectWorkshop> util = new ExcelUtil<ProjectWorkshop>(ProjectWorkshop.class);
        util.exportExcel(response, list, "标准厂房数据");
    }

    /**
     * 获取标准厂房详细信息
     */
    @RequiresPermissions("myIndustry:workshop:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectWorkshopService.selectProjectWorkshopById(id));
    }

    /**
     * 新增标准厂房
     */
    @RequiresPermissions("myIndustry:workshop:add")
    @Log(title = "标准厂房", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectWorkshop projectWorkshop)
    {
        projectWorkshop.setApprovalState(0L);
        return toAjax(projectWorkshopService.insertProjectWorkshop(projectWorkshop));
    }

    /**
     * 修改标准厂房
     */
    @RequiresPermissions("myIndustry:workshop:edit")
    @Log(title = "标准厂房", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectWorkshop projectWorkshop)
    {
        projectWorkshop.setApprovalState(0L);
        return toAjax(projectWorkshopService.updateProjectWorkshop(projectWorkshop));
    }

    /**
     * 删除标准厂房
     */
    @RequiresPermissions("myIndustry:workshop:remove")
    @Log(title = "标准厂房", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectWorkshopService.deleteProjectWorkshopByIds(ids));
    }
}
